package com.rain.qa.dao;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import com.rain.qa.pojo.Problem;
import org.springframework.data.jpa.repository.Query;

/**
 * 数据访问接口
 * @author Administrator
 *
 */
public interface ProblemDao extends JpaRepository<Problem,String>,JpaSpecificationExecutor<Problem>{

    /**
     * 根据标签id，查询最新回答的问题列表
     * @param labelid
     * @return
     */
    @Query(value = "select p from Problem p where p.id in (select problemid from Pl  where labelid = ?1 ) and p.reply > 0 order by p.replytime desc")
    Page<Problem> newList(String labelid, Pageable pageable);

    /**
     * 根据标签id，查询热门回答的问题列表
     * @param labelid
     * @return
     */
    @Query(value=" select p from Problem p where p.id in (select problemid from Pl where labelid = ?1 ) order by p.reply desc ")
    Page<Problem> hotlist(String labelid, Pageable pageable);

    /**
     * 根据标签id,查询等待回答列表
     * @param labelid
     * @return
     */
    @Query(value=" select p from Problem p  where p.id in (select problemid from Pl where labelid = ?1 ) and p.reply = 0 order by createtime desc ")
    Page<Problem> waitlist(String labelid, Pageable pageable);

}
